package com.github.binarylei.hello_world.bolt;

import org.apache.storm.topology.BasicOutputCollector;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseBasicBolt;
import org.apache.storm.tuple.Fields;
import org.apache.storm.tuple.Tuple;
import org.apache.storm.tuple.Values;

/**
 * @author: leigang
 * @version: 2018-04-07
 */
public class PrintBolt extends BaseBasicBolt {

    //private static final Log logger = LoggerFactory.getLog(PrintBolt.class);

    private static final long serialVersionUID = 1L;

    @Override
    public void execute(Tuple input, BasicOutputCollector collector) {
        // 获取上一个组件声明的Field
        String print = input.getStringByField("print");
        System.out.println("【print】:" + print);

        // 进行传递给下一个bolt
        collector.emit(new Values(print));
    }

    @Override
    public void declareOutputFields(OutputFieldsDeclarer declarer) {
        declarer.declare(new Fields("write"));
    }
}
